﻿using ApiUtils;
using LibUtils;
using ModelsUtils;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;

namespace WebApi.Controllers
{
    /// <summary>
    /// 自定义路由模版
    /// 用于解决swagger文档No operations defined in spec!问题
    /// </summary>
    // [Route("api/[controller]/[action]")]
    [WebApiExceptionFilter, RequestAuthorize]
    public class BaseController : ApiController
    {
        /// <summary>
        /// 登录用户
        /// </summary>
        /// <returns></returns>
        protected UserCache userCache
        {
            get
            {
                // var user = HttpContext.Current.Items["user"] as UserCache;
                var userid = HttpContext.Current.Items["user"].ToString();
               var user= JsonConvert.DeserializeObject<UserCache>(userid);
                if (user.IsNullOrEmpty())
                {
                    throw new Exceptions("TOKEN已失效，请重新登录 ", RespCodeEnum.TokenNotExists);
                }
                //var user = UserService.GetUserInfo(userid);
                return user;
            }
        }
    }
}